#include "findMaxSubarray.h"
int findMaxSubarray(int *data, int start, int end) {
  int mid = start + (end - start) / 2;
  int left_sum = INT_MIN, max_left_index = 0;
  int right_sum = INT_MIN, max_right_index = 0;
  int sum_result = 0;
  for (int i = mid; i >= 0; i--) {
    sum_result += data[i];
    if (sum_result > left_sum) {
      left_sum = sum_result;
      max_left_index = i;
    }
  }
  sum_result = 0;
  for (int i = mid + 1; i < end; i++) {
    sum_result += data[i];
    if (sum_result > right_sum) {
      right_sum = sum_result;
      max_right_index = i;
    }
  }
  int max_value = left_sum > right_sum ? left_sum : right_sum;
  return max_value > left_sum + right_sum ? max_value : left_sum + right_sum;
}